<template>
	<view class="buy-cat-list">
		<view class="buy-cat-item" v-for="(item, index) in list" :key="index" @click="goToDetail(item.step, item.goods_id)">
			<image class="buy-cat-item-left" :src="item.img ? IMG_URL + item.img : item.cover" mode="aspectFill"></image>
			<view class="buy-cat-item-right">
				<view class="buy-cat-name">{{ item.name }}</view>
				<view class="buy-cat-tag-list" v-if="item.cons">
					<view class="buy-cat-tag-item">{{ item.cons }}</view>
				</view>
				<view class="buy-cat-price-case" v-if="item.step == 2">
					<view class="buy-cat-price-num">
						定金￥
						<text>{{ item.first_pay }}</text>
					</view>
					<button class="buy-cat-price-btn" @click.stop="goToPay(item.goods_id)">支付尾款</button>
				</view>
				<view class="buy-cat-price-case" v-else>
					<view class="buy-cat-price-num">
						实付款￥
						<text>{{ item.total }}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
const app = getApp();
import { mycart } from '@/api/buyCat.js';
export default {
	data() {
		return {
			page: 1,
			total: 1,
			list: [],
			IMG_URL: app.globalData.IMG_URL
		};
	},
	methods: {
		async mycart() {
			const res = await mycart({
				openid: app.globalData.openid,
				page: this.page
			});
			console.log(res);
			this.list = this.list.concat(res.list);
			this.total = res.total;
		},
		// 跳转详情
		goToDetail(step, id) {
			let url = '';
			if (step == 0) {
				url = `/pagesBuyCat/earnestPay/earnestPay?goods_id=${id}`;
			} else if (step == 2) {
				url = `/pagesBuyCat/balancePay/balancePay?goods_id=${id}`;
			} else if (step == 3 || step == 4) {
				url = `/pagesBuyCat/guarantee/guarantee?goods_id=${id}`;
			} else if (step == 9) {
				url = `/pagesBuyCat/consultCustomer/consultCustomer?goods_id=${id}`;
			} else if (step == 1) {
				url = `/pagesBuyCat/freeMedical/freeMedical?goods_id=${id}`;
			}
			uni.navigateTo({
				url: url
			});
		},
		// 支付尾款
		goToPay(id) {
			uni.navigateTo({
				url: `/pagesBuyCat/balancePay/balancePay?goods_id=${id}`
			});
		}
	},
	onLoad(options) {
		this.mycart();
	},
	// 加载
	onReachBottom() {
		if (this.page === this.total) {
			return false;
		}
		this.page += 1;
		this.mycart();
	}
};
</script>

<style scoped lang="scss">
.buy-cat-list {
	padding: 24rpx 30rpx;
	.buy-cat-item {
		margin-bottom: 40rpx;
		display: flex;
		.buy-cat-item-left {
			width: 256rpx;
			height: 256rpx;
			border-radius: 20rpx;
			margin-right: 28rpx;
		}
		.buy-cat-item-right {
			flex: 1;
			display: flex;
			flex-direction: column;
			.buy-cat-name {
				font-size: 32rpx;
				font-weight: 600;
				color: #171717;
				line-height: 44rpx;
			}
			.buy-cat-tag-list {
				margin-top: 20rpx;
				display: flex;
				.buy-cat-tag-item {
					height: 40rpx;
					line-height: 40rpx;
					background: rgba(250, 131, 132, 0.2047);
					border-radius: 8rpx;
					padding: 0 16rpx;
					font-size: 24rpx;
					color: #ff6465;
					margin-right: 16rpx;
				}
			}
			.buy-cat-price-case {
				margin-top: auto;
				display: flex;
				justify-content: space-between;
				align-items: center;
				.buy-cat-price-num {
					font-size: 20rpx;
					font-weight: 500;
					color: #fa8384;
					& > text {
						font-size: 44rpx;
						font-weight: bold;
					}
				}
				.buy-cat-price-btn {
					width: 124rpx;
					height: 60rpx;
					line-height: 60rpx;
					border-radius: 12rpx;
					border: 2rpx solid #fa8384;
					background: #ffffff;
					font-size: 24rpx;
					color: #fa8384;
					margin: 0;
					padding: 0;
				}
			}
		}
	}
}
</style>
